package org.xsk.network.tcp.object;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * description: 服务器
 * <p>
 * date: 2021/6/10 12:58
 * author: x-one
 */
public class LoginServer {

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //建立连接
        ServerSocket serverSocket= new ServerSocket(8000);
        Socket socket =serverSocket.accept();

        //打开输入流
        InputStream is=socket.getInputStream();

        //读
        ObjectInputStream ois = new ObjectInputStream(is);
        User user=(User) ois.readObject();
        System.out.println(user);

        OutputStream os=socket.getOutputStream();
        String reply ="我是服务器，欢迎登陆" + user.toString();
        os.write(reply.getBytes());

        //关闭资源
        os.close();
        ois.close();
        is.close();
        socket.close();
        serverSocket.close();
    }
}
